/**
 * 
 */
package cn.bblocks.cacheTest.suport;

/** 
* @version:v1.0
* @Description: 
* @author: jzhao
* @date: 2019年11月9日下午4:06:22
*/


import java.util.List;
 
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
 
public class Page4Navigator<T> {
   //private Page<T> page4jpa2;
    //int navigatePages;
     
    int totalPages;
 
    int number;
     
    long totalElements;
     
    int size;
    
    int page;
 
    int numberOfElements;
 
    List<T> content;
 
    boolean isHasContent;
 
    boolean first;
 
    boolean last;
     
    boolean isHasNext;
 
    boolean isHasPrevious;
     
   // int[] navigatepageNums;
    
//    Pageable pageable;
     
    public Page4Navigator() {
        //这个空的分页是为了 Redis 从 json格式转换为 Page4Navigator 对象而专门提供的
    }
     
    public Page4Navigator(Page<T> page4jpa) {//navigatePages没啥用
       // this.page4jpa2 = page4jpa;
        //this.navigatePages = navigatePages;
         
        totalPages = page4jpa.getTotalPages();
         
        number  = page4jpa.getNumber() ;
         
        totalElements = page4jpa.getTotalElements();
         
        size = page4jpa.getNumberOfElements();
         
        numberOfElements = page4jpa.getNumberOfElements();
         
        content = page4jpa.getContent();
         
        isHasContent = page4jpa.hasContent();
                 
        first = page4jpa.isFirst();
         
        last = page4jpa.isLast();
         
        isHasNext = page4jpa.hasNext();
         
        isHasPrevious  = page4jpa.hasPrevious();       
        
        page = page4jpa.getNumber();
//        if(page4jpa.getPageable() != null)
//        	page = page4jpa.getPageable().getPageNumber();
        
       // calcNavigatepageNums();
         
//        pageable =  page4jpa.getPageable();
    }
 
//    private void calcNavigatepageNums() {
//        int navigatepageNums[];
//        int totalPages = getTotalPages();
//        int num = getNumber();
//        //当总页数小于或等于导航页码数时
//        if (totalPages <= navigatePages) {
//            navigatepageNums = new int[totalPages];
//            for (int i = 0; i < totalPages; i++) {
//                navigatepageNums[i] = i + 1;
//            }
//        } else { //当总页数大于导航页码数时
//            navigatepageNums = new int[navigatePages];
//            int startNum = num - navigatePages / 2;
//            int endNum = num + navigatePages / 2;
// 
//            if (startNum < 1) {
//                startNum = 1;
//                //(最前navigatePages页
//                for (int i = 0; i < navigatePages; i++) {
//                    navigatepageNums[i] = startNum++;
//                }
//            } else if (endNum > totalPages) {
//                endNum = totalPages;
//                //最后navigatePages页
//                for (int i = navigatePages - 1; i >= 0; i--) {
//                    navigatepageNums[i] = endNum--;
//                }
//            } else {
//                //所有中间页
//                for (int i = 0; i < navigatePages; i++) {
//                    navigatepageNums[i] = startNum++;
//                }
//            }
//        }  
//       // this.navigatepageNums = navigatepageNums;
//    }
 
//    public int getNavigatePages() {
//        return navigatePages;
//    }
// 
//    public void setNavigatePages(int navigatePages) {
//        this.navigatePages = navigatePages;
//    }
 
    public int getTotalPages() {
        return totalPages;
    }
 
    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }
 
    public int getNumber() {
        return number;
    }
 
    public void setNumber(int number) {
        this.number = number;
    }
 
    public long getTotalElements() {
        return totalElements;
    }
 
    public void setTotalElements(long totalElements) {
        this.totalElements = totalElements;
    }
 
    public int getSize() {
        return size;
    }
 
    public void setSize(int size) {
        this.size = size;
    }
 
    public int getNumberOfElements() {
        return numberOfElements;
    }
 
    public void setNumberOfElements(int numberOfElements) {
        this.numberOfElements = numberOfElements;
    }
 
    public List<T> getContent() {
        return content;
    }
 
    public void setContent(List<T> content) {
        this.content = content;
    }
 
    public boolean isHasContent() {
        return isHasContent;
    }
 
    public void setHasContent(boolean isHasContent) {
        this.isHasContent = isHasContent;
    }
 
    public boolean isFirst() {
        return first;
    }
 
    public void setFirst(boolean first) {
        this.first = first;
    }
 
    public boolean isLast() {
        return last;
    }
 
    public void setLast(boolean last) {
        this.last = last;
    }
 
    public boolean isHasNext() {
        return isHasNext;
    }
 
    public void setHasNext(boolean isHasNext) {
        this.isHasNext = isHasNext;
    }
 
    public boolean isHasPrevious() {
        return isHasPrevious;
    }
 
    public void setHasPrevious(boolean isHasPrevious) {
        this.isHasPrevious = isHasPrevious;
    }

	/**
	 * @return the page
	 */
	public int getPage() {
		return page;
	}

	/**
	 * @param page the page to set
	 */
	public void setPage(int page) {
		this.page = page;
	}
 
//    public int[] getNavigatepageNums() {
//        return navigatepageNums;
//    }
// 
//    public void setNavigatepageNums(int[] navigatepageNums) {
//        this.navigatepageNums = navigatepageNums;
//    }
 
}
